<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert</title>
</head>
<body style="font-family: arial">
<% 

if (request.getParameter("form") != null)
{
	String name = request.getParameter("name");
	String address = request.getParameter("address");
	String phone = request.getParameter("phone");
	if (request.getParameter("name") != ""){
	try {

		/** Loading the driver*/
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

		/** Getting Connection*/
		Connection con = DriverManager.getConnection("jdbc:odbc:jdbctest", "admin", "admin");
		con.setAutoCommit(false);
		PreparedStatement stmnt = con.prepareStatement("insert into student(name,address,phone) values(?,?,?)");
		stmnt.setString(1,name);
		stmnt.setString(2,address);
		stmnt.setString(3,phone);
		int ex = stmnt.executeUpdate();
		
		
		con.commit();
		
		
		stmnt.close();
		con.close();
		response.sendRedirect("http://localhost:8080/ex21/Ex22.jsp");
	} 
	catch (Exception e) {
		e.printStackTrace();
	}
	}
	else out.print("<br/>blank fields.");
}
	
%>
<form method=POST name="form">
<b>Name:</b>&nbsp<input type="text" name="name"/><br/><b>Address:</b>&nbsp<input type="text" name="address"><br/><b>Phone:</b>&nbsp<input type="text" name="phone">
<br/><input type="submit" value="Insert" name="form"/><input type="reset"/>
</form>
<a href="http://localhost:8080/ex21/Ex22.jsp">Back</a>
</body>
</html>